#ifndef CX_OS_CONFIG_H
#define CX_OS_CONFIG_H
#include "cx_typedef.h"

#include "at32f415.h"
#define MAX_SYSCALL_INTERRUPT_PRIORITY 0xb0
#define configASSERT(x) if((x)==0){disableInterrupt();for(;;){}}
#define configSYSCLK_MHZ 144
#define configSYSTEM_TICKS_US 1000
#define SYSTICK_LOAD ((configSYSCLK_MHZ)*configSYSTEM_TICKS_US)
#define SYSTICK_CONFIG() SysTick_Config(SYSTICK_LOAD);
#define SYS_MS_TO_TICKS(x) (1000 * x / configSYSTEM_TICKS_US)

#define portNVIC_INT_CTRL_REG		( * ( ( volatile cx_uint32_t * ) 0xe000ed04 ) )
#define portVECTACTIVE_MASK 0x000000ffUL
#define portNVIC_PENDSVSET_BIT              ( 1UL << 28UL )
#define portSY_FULL_READ_WRITE              ( 15 )

__attribute__((__always_inline__)) static inline void disableInterrupt(void)
{
    cx_uint32_t ulNewBASEPRI = MAX_SYSCALL_INTERRUPT_PRIORITY;
    asm volatile(
        "msr basepri, %0 \n"
        "dsb \n"
        "isb \n"
        :
        :"r"(ulNewBASEPRI)
        :"memory"
    );
}

__attribute__((__always_inline__)) static inline void enableInterrupt(void)
{
     cx_uint32_t ulBASEPRI =0;
    asm volatile
    (
        "msr basepri, %0 \n"
        :
        :"r"(ulBASEPRI)
        :"memory"
    );
}

#endif